
import java.io.IOException;
import java.util.AbstractMap.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import ucar.ma2.DataType;
import ucar.nc2.Dimension;
import ucar.nc2.Attribute;
import ucar.nc2.NetcdfFileWriteable;
import ucar.unidata.util.Parameter;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author brett
 */
public class ProvenanceAdapter {
    
    public static final int DOUBLE = 0;
    public static final int STRING = 1;
    
    // variables
    private int type;  // every variable must be the same type
    private static String name;
    SimpleEntry<String, Integer[]>[] vars;  // name of variables, ranges of variable
    private static NetcdfFileWriteable currentFile;
    
    public ProvenanceAdapter() {
        
    }
    
    private static void create() {
        try {
            currentFile = NetcdfFileWriteable.createNew(name);
            currentFile.addGlobalAttribute("TESTATTRIBUTE1", "TESTATTRIBUTE1VALUE");
//            int dimLength = vars[0].getValue().length;
//            Dimension[] currentDims = new Dimension[dimLength];
//            
//
//            for (int i = 0; i < dimLength; ++i) {
//                currentDims[i] = currentFile.addDimension("Dimension" + i, vars[0].getValue()[i]);
//            }
//            
//            String[] varNames = new String[vars.length];
//            for (int i = 0; i < vars.length; ++i) {
//                varNames[i] = vars[i].getKey();
//                currentFile.addVariable(varNames[i], getType(), currentDims);
//            }
            
            currentFile.create();
            currentFile.close();
            
            
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
    
    private DataType getType() {
        switch (type) {
            case DOUBLE:
                return DataType.DOUBLE;
            case STRING:
                return DataType.STRING;
            default:
                return DataType.DOUBLE;
        }
    }
    
    public static void logProvenance() {
        try {
            currentFile = NetcdfFileWriteable.openExisting(name);
//            currentFile.addGlobalAttribute("TESTATTRIBUTE1", "TESTATTRIBUTE1VALUE");
            currentFile.close();
        } catch (IOException ex) {
            Logger.getLogger(ProvenanceAdapter.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static void main(String[] args) {


        name = "PADAPTER";
        create();

//        logProvenance();

    }
    
}
